package com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.supplier;

import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.cucc.dataservice.cache.IndustryCache;
import com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.UserAttrSupplier;
import com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.UserInfoHelper;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @ClassName : IndustrySupplier
 * @Description : 行业 ORD10050
 * @Author : xie.zhengjun
 * @Date : 2021/3/14 17:23
 */
@Service
@UserAttrSupplier(attrField = LocalKeyConsts.INDUSTRY_NEW)
public class IndustryAnotherSupplier extends AbstractUserAttrSupplier{
    @Override
    public String getValue() {
        String industryVal = UserInfoHelper.getValueFromUserItemInfoMap(userInfoContext.getUserItemInfoMap(), LocalKeyConsts.INDUSTRY);
        if (KiteStringUtils.isEmpty(industryVal)) {
            industryVal = UserInfoHelper.getValueFromUserItemInfoMap(userInfoContext.getUserItemInfoMap(), LocalKeyConsts.INDUSTRY_NEW);
        }
        return industryVal;
    }

    @Override
    public String getValueDesc() {
        String industryVal = getValue();
        return Optional.ofNullable(IndustryCache.getIndustryName(industryVal)).orElse(industryVal);
    }
}
